/**
 * Copyright(c)2012 Beijing PeaceMap Co.,Ltd.
 * All right reserved. 
 */
package com.pmc.dwa.common.exception;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.NestedRuntimeException;
import org.springframework.dao.EmptyResultDataAccessException;

/**
 * @description 操作数据库异常类；数据库操作出现异常，统一由该类捕捉，可做业务处理
 * @author aokunsang
 * @date 2013-1-5
 */
public class DaoRuntimeException extends NestedRuntimeException {
	
	private static final long serialVersionUID = 1L;
	protected static Log logger = LogFactory.getLog(DaoRuntimeException.class);
	
	public DaoRuntimeException(String msg) {
		super(msg);
		logger.info((new StringBuilder()).append(getStackTrace()[0]).append(": ").append(msg).toString());
	}
	
	public DaoRuntimeException(String msg,Throwable cause){
		super(msg, cause);
		if(cause instanceof EmptyResultDataAccessException){  //jdbctemplate查询单个数据或者统计时候，没有查询到内容抛出该异常
			logger.debug((new StringBuilder()).append(getStackTrace()[0]).append(": ").append(msg).toString(), cause);
		}else{
			logger.error((new StringBuilder()).append(getStackTrace()[0]).append(": ").append(msg).toString(), cause);
		}
	}
}
